package com.ruoyi.mall.front.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.mall.entity.MallAddress;
import com.ruoyi.mall.service.IMallAddressService;
import com.ruoyi.mall.service.IMallProductService;
import com.ruoyi.mall.service.IMallPropertyService;
import com.ruoyi.mall.service.IMallValueService;
import com.ruoyi.mall.vo.MallProductVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 会员地址Controller
 * 
 * @author ruoyi
 * @date 2020-05-16
 */
@RestController
@RequestMapping("/mall/front/products")
public class FrontProductsController extends BaseController
{

    @Autowired
    private IMallProductService mallProductService;
    @Autowired
    private IMallPropertyService mallPropertyService;
    @Autowired
    private IMallValueService mallValueService;
    /**
     * 获取上架的商品列表
     * @param
     * @return
     */
    @GetMapping("/{categoryId}")
    public AjaxResult products(MallProductVo mallProductVo,@PathVariable("categoryId") Long categoryId)
    {
        if(categoryId == 0){
            mallProductVo.setCategoryId(null);
        }else{
            mallProductVo.setCategoryId(categoryId);
        }

        return AjaxResult.success(mallProductService.selectMallProductList(mallProductVo));
    }
    /**
     * 根据propertyId查商品属性值信息
     *
     * @param propertyId 商品属性值ID
     * @return 结果
     */
    @GetMapping("/values/{propertyId}")
    public AjaxResult values(@PathVariable("propertyId") Long propertyId)
    {
        return AjaxResult.success(mallValueService.getValuesByPropertyId(propertyId));
    }


}
